<template>
  <div :style="{ ...coreStyle.marginSame(8) }">
    <a-card>
      <a-form ref="accountFormQueryRef" :model="accountFormQueryModel" labelAlign="left" layout="vertical" :style="{ ...coreStyle.marginBottom(10) }">
        <a-row :gutter="16" v-show="!accountFormQueryVisible">
          <a-col :span="8">
            <a-form-item :style="{ ...coreStyle.marginBottom(-8) }">
              <a-input-search v-model:value="accountFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="accountFormQuerySubmitting" @search="accountFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
            <a-button type="link" :style="{ ...coreStyle.floatRight }" @click="accountFormQueryUpDown">
              展开
              <CoreIcon icon="akar-icons:chevron-down" :size="14" />
            </a-button>
          </a-col>
        </a-row>
        <a-row :gutter="16" v-show="accountFormQueryVisible">
          <a-col :span="8">
            <a-form-item>
              <a-input-search v-model:value="accountFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="accountFormQuerySubmitting" @search="accountFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
          </a-col>
          <a-col :span="8">
            <a-form-item label="账号">
              <a-input v-model:value="accountFormQueryModel.accountAndLike" placeholder="输入账号" />
            </a-form-item>
          </a-col>
          <!-- <a-col :span="8">
            <a-form-item label="密码">
              <a-input v-model:value="accountFormQueryModel.passwordAndLike" placeholder="输入密码" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="令牌过期 >>> 浏览器">
              <a-input-number v-model:value="accountFormQueryModel.tokenExpireBrowser" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="令牌过期 >>> 安卓App">
              <a-input-number v-model:value="accountFormQueryModel.tokenExpireAndroid" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="令牌过期 >>> 苹果App">
              <a-input-number v-model:value="accountFormQueryModel.tokenExpireIos" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="令牌过期 >>> 微信小程序">
              <a-input-number v-model:value="accountFormQueryModel.tokenExpireWechatapp" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="关联类型">
              <a-input v-model:value="accountFormQueryModel.nexusTypeAndLike" placeholder="输入关联类型" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="对象Id">
              <a-input v-model:value="accountFormQueryModel.nexusObjectIdAndLike" placeholder="输入对象Id" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="排序权重">
              <a-input-number v-model:value="accountFormQueryModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col> -->
          <a-col :span="24">
            <a-space :style="{ ...coreStyle.floatRight }">
              <a-button @click="accountFormQueryReset">
                <CoreIcon icon="ant-design:clear-outlined" :size="14" />
                重置
              </a-button>
              <a-button type="primary" ghost :loading="accountFormQuerySubmitting" @click="accountFormQuerySearch">
                <CoreIcon icon="ant-design:search-outlined" :size="14" />
                查询
              </a-button>
              <a-button type="link" @click="accountFormQueryUpDown">
                收起
                <CoreIcon icon="akar-icons:chevron-up" :size="14" />
              </a-button>
            </a-space>
          </a-col>
        </a-row>
      </a-form>
      <a-space>
        <a-button type="primary" ghost @click="accountAdd">
          <CoreIcon icon="carbon:add-alt" :size="14" />
          新增
        </a-button>
        <a-button type="dashed" @click="accountUpdate" v-if="accountListSelectLength === 1">
          <CoreIcon icon="ri:brush-line" :size="14" />
          修改
        </a-button>
        <a-popconfirm title="确认删除？" placement="bottom" @confirm="accountDelete" v-if="accountListSelectLength > 0">
          <a-button type="dashed" danger>
            <CoreIcon icon="jam:delete" :size="14" />
            删除
          </a-button>
        </a-popconfirm>
        <a-button @click="accountDetailInfo" v-if="accountListSelectLength === 1">
          <CoreIcon icon="heroicons-outline:light-bulb" :size="14" />
          详情
        </a-button>
      </a-space>
      <a-space :style="{ ...coreStyle.floatRight }">
        <a-button type="link" shape="circle" @click="accountListGetDataSet">
          <CoreIcon icon="ci:refresh" :size="22" />
        </a-button>
      </a-space>
      <a-table
        rowKey="id"
        :columns="accountListColumns"
        :data-source="accountListDataSet"
        :loading="accountListLoading"
        :pagination="false"
        bordered
        :customRow="accountListCustomRow"
        :row-selection="{ fixed: true, selectedRowKeys: accountListSelectedRowKeys, onChange: accountListRowOnChange }"
        :scroll="{ x: '100%', y: 550 }"
        :style="{ ...coreStyle.marginTop(10) }"
      >
        <template #nexusTypeData="{ text }">
          <span>{{ coreToolStore.getDictDisplayName('accountNexusType', text) }}</span>
        </template>
      </a-table>
      <a-pagination
        v-model:current="accountListDataPage"
        v-model:pageSize="accountListDataRows"
        :total="accountListDataCount"
        show-size-changer
        show-quick-jumper
        :page-size-options="[ ...coreStyle.antdPaginationPageSizeOptions ]"
        :show-total="(total, range) => coreStyle.antdPaginationShowTotal(total, range)"
        :style="{ ...coreStyle.marginTop(10), ...coreStyle.textAlignCenter }"
        @change="accountListPaginationChange"
        @showSizeChange="accountListPaginationShowSizeChange"
        v-if="accountListPaginationVisible"
      >
      </a-pagination>
      <p :style="{ ...coreStyle.marginTop(14), ...coreStyle.marginBottom(6), ...coreStyle.textAlignCenter }" v-if="!accountListPaginationVisible">
        {{ coreStyle.antdPaginationShowTotal(accountListDataCount) }}
      </p>
    </a-card>
    <a-drawer
      v-model:visible="accountEditDrawerVisible"
      title="编辑账号信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
      @close="accountEditDrawerOnClose"
    >
      <a-form ref="accountFormRef" :model="accountFormModel" :rules="accountFormRules" labelAlign="left" layout="vertical">
        <a-row :gutter="16">
          <a-col :span="12">
            <a-form-item label="账号" name="account">
              <a-input v-model:value="accountFormModel.account" placeholder="输入账号" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="排序权重" name="weightOrder">
              <a-input-number v-model:value="accountFormModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="密码" name="password">
              <a-input v-model:value="accountFormModel.password" placeholder="输入密码" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
          </a-col>
          <a-col :span="24">
            <!-- <a-form-item label="关联类型" name="nexusType">
              <a-input v-model:value="accountFormModel.nexusType" placeholder="输入关联类型" />
            </a-form-item> -->
            <Dict v-model="accountFormModel.nexusType" dictKey="accountNexusType" formItemName="nexusType" @change="accountNexusTypeDictSelectChange" />
          </a-col>
          <!-- <a-col :span="24">
            <a-form-item label="对象Id" name="nexusObjectId">
              <a-input v-model:value="accountFormModel.nexusObjectId" placeholder="输入对象Id" />
            </a-form-item>
          </a-col> -->
          <a-col :span="24" v-if="'staff' === accountFormModel.nexusType">
            <a-form-item label="员工" name="nexusObjectId">
              <a-select v-model:value="accountFormModel.nexusObjectId" optionFilterProp="title" show-search allowClear placeholder="请选择" :style="{ ...coreStyle.width('100%') }">
                <a-select-option v-for="item in accountStaffSelectData" :value="item.id" :key="item.id" :title="item.staffName + ' - [' + item.mphoneNo + ']'">
                  {{ item.staffName + ' - [' + item.mphoneNo + ']' }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="24" v-if="'usr' === accountFormModel.nexusType">
            <a-form-item label="用户" name="nexusObjectId">
              <a-select v-model:value="accountFormModel.nexusObjectId" optionFilterProp="title" show-search allowClear placeholder="请选择" :style="{ ...coreStyle.width('100%') }">
                <a-select-option v-for="item in accountUsrSelectData" :value="item.id" :key="item.id" :title="item.usrname + ' - [' + coreToolStore.getDictDisplayName('usrType', item.usrType) + ']'">
                  {{ item.usrname + ' - [' + coreToolStore.getDictDisplayName('usrType', item.usrType) + ']' }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="令牌过期 >>> 浏览器 (毫秒数)" name="tokenExpireBrowser">
              <a-input-number v-model:value="accountFormModel.tokenExpireBrowser" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="令牌过期 >>> 安卓App (毫秒数)" name="tokenExpireAndroid">
              <a-input-number v-model:value="accountFormModel.tokenExpireAndroid" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="令牌过期 >>> 苹果App (毫秒数)" name="tokenExpireIos">
              <a-input-number v-model:value="accountFormModel.tokenExpireIos" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="令牌过期 >>> 微信小程序 (毫秒数)" name="tokenExpireWechatapp">
              <a-input-number v-model:value="accountFormModel.tokenExpireWechatapp" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button @click="accountFormReset">
            <CoreIcon icon="ant-design:clear-outlined" :size="14" />
            重置
          </a-button>
          <a-button type="primary" ghost :loading="accountFormSaveSubmitting" @click="accountFormNextAdd">
            <CoreIcon icon="tabler:player-track-next" :size="14" />
            继续录入
          </a-button>
          <a-button type="primary" ghost :loading="accountFormSaveSubmitting" @click="accountFormSave">
            <CoreIcon icon="ant-design:save-outlined" :size="14" />
            保存
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="accountDetailDrawerVisible"
      title="账号详细信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
    >
      <a-space direction="vertical" :size="20" :style="{ ...coreStyle.width('100%') }">
        <a-descriptions title="基础信息" :column="2" bordered>
          <a-descriptions-item label="账号" :span="1">{{ accountDetailModel.account }}</a-descriptions-item>
          <a-descriptions-item label="密码" :span="1">{{ accountDetailModel.password }}</a-descriptions-item>
          <a-descriptions-item label="关联类型" :span="1">{{ coreToolStore.getDictDisplayName('accountNexusType', accountDetailModel.nexusType) }}</a-descriptions-item>
          <a-descriptions-item label="排序权重" :span="1">{{ accountDetailModel.weightOrder }}</a-descriptions-item>
          <!-- <a-descriptions-item label="对象Id" :span="2">{{ accountDetailModel.nexusObjectId }}</a-descriptions-item> -->
          <a-descriptions-item label="令牌过期 >>> 浏览器" :span="2">{{ accountDetailModel.tokenExpireBrowser }}</a-descriptions-item>
          <a-descriptions-item label="令牌过期 >>> 安卓App" :span="2">{{ accountDetailModel.tokenExpireAndroid }}</a-descriptions-item>
          <a-descriptions-item label="令牌过期 >>> 苹果App" :span="2">{{ accountDetailModel.tokenExpireIos }}</a-descriptions-item>
          <a-descriptions-item label="令牌过期 >>> 微信小程序" :span="2">{{ accountDetailModel.tokenExpireWechatapp }}</a-descriptions-item>
        </a-descriptions>
      </a-space>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" @click="accountDetailUpdate">
            <CoreIcon icon="ri:brush-line" :size="14" />
            修改
          </a-button>
        </a-space>
      </div>
    </a-drawer>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component'
import { mapStores } from 'pinia'
import { useCoreToolStore } from '/@/store/modules/cn/core/tool/coreToolStore'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import coreTool from '/@/tool/coreTool'

import { useAccountStore } from '/@/store/modules/cn/core/sign/accountStore'

import type { Account } from '/@/model/cn/core/sign/eo/Account'
import { toAccount } from '/@/model/cn/core/sign/eo/Account'

import type { AccountQO } from '/@/model/cn/core/sign/qo/AccountQO'
import { toAccountQO } from '/@/model/cn/core/sign/qo/AccountQO'

import type { AccountVO } from '/@/model/cn/core/sign/vo/AccountVO'
import { toAccountVO } from '/@/model/cn/core/sign/vo/AccountVO'

import { useUsrStore } from '/@/store/modules/cn/core/sign/usrStore'

import type { Usr } from '/@/model/cn/core/sign/eo/Usr'
import type { UsrQO } from '/@/model/cn/core/sign/qo/UsrQO'

import { useStaffStore } from '/@/store/modules/cn/core/sign/staffStore'

import type { Staff } from '/@/model/cn/core/sign/eo/Staff'
import type { StaffQO } from '/@/model/cn/core/sign/qo/StaffQO'

@Options({
  name: 'CoreAccount',
  components: {
  },
  computed: {
    ...mapStores(useCoreToolStore, useAccountStore, useStaffStore, useUsrStore),
  },
})
export default class CoreAccount extends Vue {

  accountListDataSet: Array<AccountVO> = []

  accountListColumns: Array<object> = [
    {
      title: '账号',
      dataIndex: 'account',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    // {
    //   title: '密码',
    //   dataIndex: 'password',
    //   align: 'center',
    //   // ellipsis: true,
    //   // width: 200,
    // },
    // {
    //   title: '令牌过期 >>> 浏览器',
    //   dataIndex: 'tokenExpireBrowser',
    //   align: 'center',
    //   // ellipsis: true,
    //   // width: 200,
    // },
    // {
    //   title: '令牌过期 >>> 安卓App',
    //   dataIndex: 'tokenExpireAndroid',
    //   align: 'center',
    //   // ellipsis: true,
    //   // width: 200,
    // },
    // {
    //   title: '令牌过期 >>> 苹果App',
    //   dataIndex: 'tokenExpireIos',
    //   align: 'center',
    //   // ellipsis: true,
    //   // width: 200,
    // },
    // {
    //   title: '令牌过期 >>> 微信小程序',
    //   dataIndex: 'tokenExpireWechatapp',
    //   align: 'center',
    //   // ellipsis: true,
    //   // width: 200,
    // },
    {
      title: '关联类型',
      dataIndex: 'nexusType',
      align: 'center',
      slots: { customRender: 'nexusTypeData' },
      // ellipsis: true,
      width: 100,
    },
    // {
    //   title: '对象Id',
    //   dataIndex: 'nexusObjectId',
    //   align: 'center',
    //   // ellipsis: true,
    //   // width: 200,
    // },
    {
      title: '排序权重',
      dataIndex: 'weightOrder',
      align: 'center',
      // ellipsis: true,
      width: 100,
    },
  ]

  accountListLoading: boolean = false

  accountListSelectedRowKeys: string[] = []

  accountListSelectData: Array<AccountVO> = []

  accountListSelectLength: number = 0

  accountListSelectCurrentRowIndex: number = -1

  accountListSelectCurrentRowData: AccountVO = toAccountVO()

  accountListPaginationVisible: boolean = true

  accountListDataPage: number = 1

  accountListDataRows: number = 10

  accountListDataCount: number = 0

  accountListRowOnChange(selectedRowKeys, selectedRows) {
    this.accountListSelectedRowKeys = [ ...selectedRowKeys ]
    this.accountListSelectData = [ ...selectedRows ]
    this.accountListSelectLength = selectedRows.length
  }

  accountListCustomRow(record, index) {
    return {
      'class': index === this.accountListSelectCurrentRowIndex ? 'ant-table-row-selected' : '',
      onClick: (event) => {
        this.accountListSelectCurrentRowIndex = index
        this.accountListSelectCurrentRowData = { ...record }
        let selectedRowKeys = [ ...this.accountListSelectedRowKeys ]
        let selectedRows = [ ...this.accountListSelectData ]
        if (selectedRowKeys.includes(record.id)) {
          this.accountListRowOnChange([ ...selectedRowKeys.filter(eo => { return eo !== record.id }) ], [ ...selectedRows.filter(eo => { return eo.id !== record.id }) ])
        } else {
          selectedRowKeys.push(record.id)
          selectedRows.push(record)
          this.accountListRowOnChange([ ...new Set(selectedRowKeys) ], [ ...new Set(selectedRows) ])
        }
      },
      onDblclick: (event) => {
        this.accountStore.pkVo(this.$toParam<AccountQO>({ id: this.accountListSelectCurrentRowData.id } as AccountQO)).then((res: Res<AccountVO>) => {
          if (res.succ) {
            this.accountDetailModel = { ...res.data[0] }
            this.accountDetailDrawerVisible = true
          } else {
            this.$message.error(res.msg, 6)
          }
        })
      },
    }
  }

  accountListGetDataSet() {
    this.accountListLoading = true
    this.accountListRowOnChange([], [])
    this.accountListSelectCurrentRowIndex = -1
    this.accountListSelectCurrentRowData = toAccountVO()
    this.accountStore.pagingVo(this.$toParam<AccountQO>({ weightOrderAsc: 'y' } as AccountQO, this.accountListDataPage, this.accountListDataRows)).then((res: Res<AccountVO>) => {
      if (res.succ) {
        this.accountListPaginationVisible = true
        this.accountListDataSet = [ ...res.data ]
        this.accountListDataCount = res.count
        setTimeout(() => { this.accountListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.accountListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.accountListLoading = false }, 500)
    })
  }

  accountListPaginationChange() {
    this.accountListGetDataSet()
  }

  accountListPaginationShowSizeChange() {
    this.accountListGetDataSet()
  }

  accountFormQueryVisible: boolean = false

  accountFormQuerySubmitting: boolean = false

  accountFormQueryModel: AccountQO = toAccountQO()

  accountFormQueryUpDown() {
    this.accountFormQueryVisible = !this.accountFormQueryVisible
  }

  accountFormQueryReset() {
    if (this.$refs.accountFormQueryRef) {
      this.$refs.accountFormQueryRef.resetFields()
      this.accountFormQueryModel = toAccountQO()
    }
  }

  accountFormQuerySearch() {
    this.accountFormQuerySubmitting = true
    this.accountListLoading = true
    this.accountListRowOnChange([], [])
    this.accountListSelectCurrentRowIndex = -1
    this.accountListSelectCurrentRowData = toAccountVO()
    this.accountStore.queryVo(this.$toParam<AccountQO>(this.$toSearch({ ...this.accountFormQueryModel }))).then((res: Res<AccountVO>) => {
      if (res.succ) {
        this.accountListPaginationVisible = false
        this.accountListDataSet = [ ...res.data ]
        this.accountListDataCount = res.count
        setTimeout(() => { this.accountFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.accountListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.accountFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.accountListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.accountFormQuerySubmitting = false }, 5000)
      setTimeout(() => { this.accountListLoading = false }, 500)
    })
  }

  accountEditDrawerVisible: boolean = false

  accountFormSaveSubmitting: boolean = false

  accountFormSaveContinue: boolean = false

  accountFormModel: Account = toAccount()

  accountFormRules: object = {
    account: [
      { type: 'string', required: true, message: '账号不能为空！', trigger: ['change', 'blur'] },
    ],
    password: [
      { type: 'string', required: true, message: '密码不能为空！', trigger: ['change', 'blur'] },
    ],
    // tokenExpireBrowser: [
    //   { type: 'number', required: true, message: '令牌过期 >>> 浏览器不能为空！', trigger: ['change', 'blur'] },
    // ],
    // tokenExpireAndroid: [
    //   { type: 'number', required: true, message: '令牌过期 >>> 安卓App不能为空！', trigger: ['change', 'blur'] },
    // ],
    // tokenExpireIos: [
    //   { type: 'number', required: true, message: '令牌过期 >>> 苹果App不能为空！', trigger: ['change', 'blur'] },
    // ],
    // tokenExpireWechatapp: [
    //   { type: 'number', required: true, message: '令牌过期 >>> 微信小程序不能为空！', trigger: ['change', 'blur'] },
    // ],
    // nexusType: [
    //   { type: 'string', required: true, message: '关联类型不能为空！', trigger: ['change', 'blur'] },
    // ],
    // nexusObjectId: [
    //   { type: 'string', required: true, message: '对象Id不能为空！', trigger: ['change', 'blur'] },
    // ],
    // weightOrder: [
    //   { type: 'number', required: true, message: '排序权重不能为空！', trigger: ['change', 'blur'] },
    // ],
  }

  accountStaffSelectData: Array<Staff> = []

  accountUsrSelectData: Array<Usr> = []

  accountNexusTypeDictSelectChange(value, is) {
    if (!is) {
      this.accountFormModel.nexusObjectId = null
    }
    if ('staff' === value) {
      this.staffStore.query(this.$toParam<StaffQO>({ weightOrderAsc: 'y' } as StaffQO)).then((res: Res<Staff>) => {
        if (res.succ) {
          this.accountStaffSelectData = [ ...res.data ]
        } else {
          this.$message.error(res.msg, 6)
        }
      })
    }
    if ('usr' === value) {
      this.usrStore.query(this.$toParam<UsrQO>({ weightOrderAsc: 'y' } as UsrQO)).then((res: Res<Usr>) => {
        if (res.succ) {
          this.accountUsrSelectData = [ ...res.data ]
        } else {
          this.$message.error(res.msg, 6)
        }
      })
    }
  }

  accountFormReset() {
    if (this.$refs.accountFormRef) {
      this.$refs.accountFormRef.resetFields()
      this.accountFormModel = toAccount()
    }
  }

  accountFormSubmit() {
    this.accountFormSaveSubmitting = true
    this.$refs.accountFormRef.validate().then(() => {
      this.accountFormModel.password = coreTool.encodeAES(this.accountFormModel.password, coreTool.aesKey)
      if (this.accountFormModel.id) {
        this.accountStore.update(this.$toParam<Account>(this.accountFormModel)).then((res: Res<Account>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.accountFormReset()
            this.accountFormSaveSubmitting = false
            if (!this.accountFormSaveContinue) {
              this.accountEditDrawerVisible = false
              this.accountListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.accountFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.accountFormSaveSubmitting = false }, 3000)
        })
      } else {
        this.accountStore.save(this.$toParam<Account>(this.accountFormModel)).then((res: Res<Account>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.accountFormReset()
            this.accountFormSaveSubmitting = false
            if (!this.accountFormSaveContinue) {
              this.accountEditDrawerVisible = false
              this.accountListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.accountFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.accountFormSaveSubmitting = false }, 3000)
        })
      }
    }).catch(() => {
      setTimeout(() => { this.accountFormSaveSubmitting = false }, 3000)
    })
  }

  accountFormSave() {
    this.accountFormSaveContinue = false
    this.accountFormSubmit()
  }

  accountFormNextAdd() {
    this.accountFormSaveContinue = true
    this.accountFormSubmit()
  }

  accountAdd() {
    if (this.accountFormModel.id) {
      this.accountFormReset()
    }
    this.accountEditDrawerVisible = true
  }

  accountUpdate() {
    this.accountStore.pk(this.$toParam<AccountQO>({ id: this.accountListSelectData[0].id } as AccountQO)).then((res: Res<Account>) => {
      if (res.succ) {
        this.accountFormReset()
        this.accountFormModel = { ...res.data[0] }
        this.accountFormModel.password = coreTool.decodeAES(this.accountFormModel.password, coreTool.aesKey)
        this.accountNexusTypeDictSelectChange(this.accountFormModel.nexusType, true)
        this.accountEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  accountEditDrawerOnClose() {
    if (this.accountFormSaveContinue) {
      this.accountFormSaveContinue = false
      this.accountListGetDataSet()
    }
  }

  accountDelete() {
    let param: Array<Account> = []
    this.accountListSelectData.forEach((eo: AccountVO) => {
      param.push({ id: eo.id } as Account)
    })
    this.accountStore.removeBatch(this.$toParam<Account>(param)).then((res: Res<Account>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.accountListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  accountDetailDrawerVisible: boolean = false

  accountDetailModel: AccountVO = toAccountVO()

  accountDetailInfo() {
    this.accountStore.pkVo(this.$toParam<AccountQO>({ id: this.accountListSelectData[0].id } as AccountQO)).then((res: Res<AccountVO>) => {
      if (res.succ) {
        this.accountDetailModel = { ...res.data[0] }
        this.accountDetailDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  accountDetailUpdate() {
    this.accountStore.pk(this.$toParam<AccountQO>({ id: this.accountDetailModel.id } as AccountQO)).then((res: Res<Account>) => {
      if (res.succ) {
        this.accountFormReset()
        this.accountFormModel = { ...res.data[0] }
        this.accountFormModel.password = coreTool.decodeAES(this.accountFormModel.password, coreTool.aesKey)
        this.accountNexusTypeDictSelectChange(this.accountFormModel.nexusType, true)
        this.accountDetailDrawerVisible = false
        this.accountEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  mounted() {
    this.accountListGetDataSet()
  }

}
</script>

<style scoped lang="less">

</style>
